/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.unkerja;

import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class UnKerjaPopupWnd extends ClassApplicationModule {

    private Listbox lstboxUnitKerja;
    private Textbox txtboxKeySearch;
    private UnKerjaDAO unDao;

    public UnKerjaPopupWnd() {
        unDao = new UnKerjaDAOImpl();
    }

    public void onCreate() throws Exception {
        lstboxUnitKerja = (Listbox) getFellow("lstboxUnitKerja");
        txtboxKeySearch = (Textbox) getFellow("txtboxKeySearch");
        loadUnKerja();
    }

    private void loadUnKerja() throws Exception {
        lstboxUnitKerja.getItems().clear();
        for (UnKerja un : unDao.listAll(txtboxKeySearch.getValue())) {
            Listitem item = new Listitem();
            item.setValue(un);
            item.appendChild(new Listcell(un.getKdUnitKerja()));
            item.appendChild(new Listcell(un.getNamaUnitKerja()));
            lstboxUnitKerja.appendChild(item);
        }
    }

    public void lstboxUnitKerjaOnSelect() throws Exception {
        UnKerja un = (UnKerja) lstboxUnitKerja.getSelectedItem().getValue();
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxKodeUnitKerja = (Textbox)window.getFellow("txtboxKodeUnitKerja");
        Textbox txtboxUnitKerja = (Textbox)window.getFellow("txtboxUnitKerja");
        txtboxUnitKerja.setValue(un.getNamaUnitKerja());
        txtboxKodeUnitKerja.setValue(un.getKdUnitKerja());
        this.detach();
    }
}
